package com.dayanxs.Controller;

import com.dayanxs.Utils.AESCryptoUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
//不对外开放 aes解密Test类
@RestController
@RequestMapping("/aes")
public class AesDecrypt {

    @GetMapping("/decode")
    public ResponseEntity<?> decode(@RequestParam String aes) {
        try {
            // 使用 AES 解密
            String decryptedData = AESCryptoUtil.decrypt(aes);

            // 创建返回的 JSON 数据
            Map<String, String> response = new HashMap<>();
            response.put("decryptedData", decryptedData);

            return ResponseEntity.ok(response);
        } catch (Exception e) {
            // 如果验证失败，返回 JSON 格式的错误消息
            Map<String, String> errorResponse = new HashMap<>();
            errorResponse.put("error", "Decryption error");
            return ResponseEntity.status(500).body(errorResponse);
        }
    }
}
